home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / DES.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-29  |  2KB  |  65 lines

  1. PROCEDURE des(input,key: gl64array; VAR newkey: integer;
  2.          isw: integer; VAR jotput: gl64array);
  3. (* Programs using routine DES must define the type
  4. TYPE
  5.    gl32array = ARRAY [1..32] OF integer;
  6.    gl64array = ARRAY [1..64] OF integer;
  7.    gl48array = ARRAY [1..48] OF real;
  8. in the main routine. They must also declare the variables
  9. VAR
  10.    ip,ipm: gl64array;
  11.    desflg: boolean;
  12. and initialize desflg to true. The values of ip and ipm are read from
  13. the file desinp.dat whose contents are listed at the end of this routine.
  14. The procedure GLOPEN is used to assign desinp.dat to infile and open the file
  15. for reading. *)
  16. VAR
  17.    j,ii,ic,i: integer;
  18.    titmp,icf: gl32array;
  19.    itmp: gl64array;
  20.    kns: ARRAY[1..48,1..16] OF integer;
  21.    tkns: gl48array;
  22.    infile: text;
  23. BEGIN
  24.    IF desflg THEN BEGIN
  25.       desflg := false;
  26.       glopen(infile,'desinp.dat');
  27.       FOR i := 1 TO 64 DO read(infile,ip[i]);
  28.       FOR i := 1 TO 64 DO read(infile,ipm[i]);
  29.       close(infile)
  30.    END;
  31.    IF (newkey <> 0) THEN BEGIN
  32.       newkey := 0;
  33.       FOR i := 1 TO 16 DO BEGIN
  34.          ks(key,i,tkns);
  35.          FOR j := 1 TO 48 DO kns[j,i] := tkns[j]
  36.       END
  37.    END;
  38.    FOR j := 1 TO 64 DO itmp[j] := input[ip[j]];
  39.    FOR i := 1 TO 16 DO BEGIN
  40.       ii := i;
  41.       IF (isw = 1) THEN ii := 17-i;
  42.       FOR j := 1 TO 48 DO tkns[j] := kns[j,ii];
  43.       FOR j := 1 TO 32 DO titmp[j] := itmp[32+j];
  44.       cyfun(titmp,tkns,icf);
  45.       FOR j := 1 TO 32 DO BEGIN
  46.          ic := icf[j]+itmp[j];
  47.          itmp[j] := itmp[j+32];
  48.          itmp[j+32] := abs(ic MOD 2)
  49.       END
  50.    END;
  51.    FOR j := 1 TO 32 DO BEGIN
  52.       ic := itmp[j];
  53.       itmp[j] := itmp[j+32];
  54.       itmp[j+32] := ic
  55.    END;
  56.    FOR j := 1 TO 64 DO jotput[j] := itmp[ipm[j]]
  57. END;
  58. (* Contents of the file desinp.dat
  59. 58 50 42 34 26 18 10 2 60 52 44 36 28 20 12 4 62 54 46
  60. 38 30 22 14 6 64 56 48 40 32 24 16 8 57 49 41 33 25 17 9 1 59 51
  61. 43 35 27 19 11 3 61 53 45 37 29 21 13 5 63 55 47 39 31 23 15 7
  62. 40 8 48 16 56 24 64 32 39 7 47 15 55 23 63 31 38 6 46 14
  63. 54 22 62 30 37 5 45 13 53 21 61 29 36 4 44 12 52 20 60 28 35 3
  64. 43 11 51 19 59 27 34 2 42 10 50 18 58 26 33 1 41 9 49 17 57 25 *)
  65.